<?php

$xmlDoc = new DOMDocument();

$alerts = $xmlDoc->appendChild(
	  $xmlDoc->createElement("alerts"));


if (!$file = fopen("/var/www/FIEM/correlator/matched_log","r")) {
//echo "Echec de l'ouverture du fichier";

exit;
}
else 
{
	$cmp = 0;
	while(!feof($file)) 
	{
	 
		$lines = fgets($file,1024);
		$res = explode("-", $lines);		 	

		if( $res[0] != "" ) 
		{	

			$alert = $alerts->appendChild(
				      $xmlDoc->createElement("alert"));
			$alert->appendChild(
			    $xmlDoc->createElement("Id", $res[0]));
			$alertAttributes = $alert->appendChild(
				      $xmlDoc->createElement("alertAttributes"));
			$alertAttributes->appendChild(
			    $xmlDoc->createElement("event", $res[1]));
			$alertAttributes->appendChild(
			    $xmlDoc->createElement("level", $res[2]));
			$alertAttributes->appendChild(
			    $xmlDoc->createElement("type", $res[3]));
			$alertAttributes->appendChild(
			    $xmlDoc->createElement("description", $res[4]));
			$line = $alertAttributes->appendChild(
			    $xmlDoc->createElement("line"));


			$log_line = explode("|", $res[5]);		 	
 
		 
			  $line->appendChild(
			    $xmlDoc->createElement("User", $log_line[1]));
			  $line->appendChild(
			    $xmlDoc->createElement("Status", $log_line[2]));
			  $line->appendChild(
			    $xmlDoc->createElement("App", $log_line[3]));
			  $line->appendChild(
			    $xmlDoc->createElement("Filename", $log_line[4]));	


			
		
		}
		else
		{
			header("Content-Type: text/xml");
			$xmlDoc->formatOutput = true;
			break;
			 
		}

	}
	fclose($file);  
}
echo $xmlDoc->saveXML();
 
?>



